/****************************************************
    Author:            龙之介
    CreatTime:    2020/12/26 14:52:42
    Description:     Nothing
*****************************************************/

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using UnityEngine.UI;
using ZYKTool;
using System.Linq;
using HQL;


namespace LongZhiJie
{
    public class TapTap升级系统 : MonoBehaviour
    {
        #region 常量
        #endregion

        #region 事件
        #endregion

        #region 字段
        #endregion


        #region 属性 
        private GunManger _GunManger;
        Transform _updateMenu;
        List<Transform> _UpdateList;
        Transform _updatelistParent;
        List<bool> _used;
        #endregion


        #region 方法 
        public void Init()
        {
            _GunManger = TapTapStaticValue.Player.transform.Find("Body").Find("GunManger").GetOrAddComponent<GunManger>();

            _updatelistParent = transform.Find("升级列表");
            _UpdateList = new List<Transform>();
            foreach (Transform item in _updatelistParent)
            {
                _UpdateList.Add(item);
                item.gameObject.SetActive(false);
            }
            _updateMenu = transform.Find("升级菜单");
            _updateMenu.Find("WuQi").transform.GetOrAddComponent<Button>().onClick.AddListener(UpdateGun);
            _updateMenu.Find("SuiJiShiJian").transform.GetOrAddComponent<Button>().onClick.AddListener(UpdateSuiJiShiJian);
            _updateMenu.Find("ZhuFu").transform.GetOrAddComponent<Button>().onClick.AddListener(UpdateZhuFu);
            _used = new List<bool>();
            for (int i=0;i<8;i++)
            {
                _used.Add(false);
            }
        }
        private void UpdateGun()
        {
            //Debug.LogError("Wuqi");

            ClickEnd(_GunManger.UpdateGun());
        }
        private void UpdateZhuFu()
        {
            /*
             *      Blood = blood;
       
        Speed = 10;
        重力转换冷却 = 2;
             */
            string test = "??";
            switch (UnityEngine.Random.Range(0, 3))
            {
                case 0:int temp = UnityEngine.Random.Range(3, 5);  TapTapStaticValue.PlayerAttributes.Blood += temp; test = "玩家血量增加"+temp.ToString(); break;
                case 1: float lengque = 0.2f; ; TapTapStaticValue.PlayerAttributes.重力转换冷却 -= lengque; test = "重力转换冷却减少" + lengque.ToString(); break;
                case 2: float speed = UnityEngine.Random.Range(5, 7); ; TapTapStaticValue.PlayerAttributes.Speed+= speed; test = "玩家移速"+ speed.ToString(); break;
            }
            ClickEnd(test);
        }


        private void UpdateSuiJiShiJian()
        {
            //Debug.LogError("SuiJiShiJian");
            int index;
            while(true)
            {
                index = UnityEngine.Random.Range(0, 5);
                if(_used[index])
                {
                    continue;
                }
                _used[index] = true;
                string test = "中奖了，无货";

                switch(index)
                {
                    case 0:
                        foreach(BossAttributes bossBase in TapTapStaticValue.BossAttributes.Values)
                        {
                            bossBase.Blood -= bossBase.Blood * 0.3f;
                        }
                         test= "所有boss血量减少30%"; break;
                    case 1: TapTapStaticValue.UpdateRandom后座力 = 0; test = "玩家取消后座力"; break;
                    case 2:; TapTapStaticValue.UpdateRandom玩家攻击可以移动 = true; test = "玩家攻击可以移动"; break;
                    case 3: TapTapStaticValue.UpdateRandom重力切换改为闪现=true; test = "玩家的重力切换改为闪现"; break;
                }
                ClickEnd(test);
                break;
            }
            //所有boss血量减少20%
            //TapTapStaticValue.BossAttributes[0].Blood
            //玩家后座力无
            //玩家攻击可以移动
            //玩家受到的伤害后3S无敌
            
          
        }//  
        private void ClickEnd(string test)
        {
            TapTapStaticValue.PlaySound();
            _updateMenu.gameObject.SetActive(false);
            foreach (Transform item in _UpdateList)
            {
                if (!item.gameObject.activeSelf)
                {
                    item.gameObject.SetActive(true);
                    item.transform.GetChild(0).GetOrAddComponent<Text>().text = test;
                    Transform Bosses = GameObject.Find("Boss").transform;
                    foreach (Transform boss in Bosses)
                    {
                        if (boss.tag == "Enemy")
                        {
                            boss.gameObject.SetActive(true);
                            ZYKTool.Timer.ZYKTimerSystemTool.Instance.ZYKTimerAddTimerTask(
                                () => {
                                    BossBase adad = boss.transform.GetOrAddComponent<BossBase>();
                                    TapTapStaticValue.BossCurrent = adad;
                                    adad.Init();
                                }, 1, 1);
                 
             
                            break;
                        }
                    }
                    return;
                }
            }

        }
        public void TapTapStartUpdate()
        {
            
            _updateMenu.gameObject.SetActive(true);
            TapTapStaticValue.PlayerAttributes.Blood += 3;
            
        }
        #endregion

        #region Unity回调
        #endregion

        #region 事件回调

        #endregion

        #region 帮助方法
        #endregion

    }
}